<?php
/* 
	This file is Copyright Matthew Wilkinson 2009.
	
	This file is part of Oxygen.

	Oxygen is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License version 3 as published by
	the Free Software Foundation at http://www.gnu.org/licenses/gpl-3.0.html

	Oxygen is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

*/

	Class User
		{
		
		private $id;
		private $data = Array();
		
		public static $enable_events = TRUE;
		
		public function __construct($id = 0)
			{
			if ($id !== 0)
				{
				$userdata = Database::query('SELECT * FROM users WHERE id={int}', $id);
				$this->id = $userdata[0]['id'];
				$this->data = $userdata[0];
				}
			else
				{
				$userdata = Database::query('SELECT * FROM users LIMIT 1');
				foreach ($userdata as $key=>$value)
					{
					$this->data[$key] = null;
					}
				}
			}
		
		public function __get($prop)
			{
			if (isset($this->data[$prop]))
				{
				return $this->data[$prop];
				}
			}
		
		public function __set($prop, $value)
			{
			if ($prop !== 'id' AND isset($this->data[$prop]))
				{
				$this->data[$prop] = $value;
				if (User::$enable_events)
					{
					Events::Announce(Events::USER_CHANGE, &$this);
					}
				return TRUE;
				}
			else
				{
				return FALSE;
				}
			}
		
		
		
		}

?>